package com.cci.kangdao.fieldService.service.impl;

import com.cci.kangdao.dao.UserTDao;
import com.cci.kangdao.dao.model.UserT;
import com.cci.kangdao.fieldService.dao.FieldServiceItemDao;
import com.cci.kangdao.fieldService.dao.FieldServiceWorkOrderDao;
import com.cci.kangdao.fieldService.dao.FieldServiceWorkOrderFlowDao;
import com.cci.kangdao.fieldService.model.FieldServiceItem;
import com.cci.kangdao.fieldService.model.FieldServiceWorkOrder;
import com.cci.kangdao.fieldService.model.FieldServiceWorkOrderFlow;
import com.cci.kangdao.fieldService.service.FieldServiceNotifyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author William Du
 * @date 2020/8/3
 */
@Service
public class FieldServiceNotifyServiceImpl implements FieldServiceNotifyService {

    @Resource
    private FieldServiceItemDao fieldServiceItemDao;

    @Resource
    private FieldServiceWorkOrderDao fieldServiceWorkOrderDao;

    @Resource
    private UserTDao userTDao;

    @Override
    public Map<String, Object> getNotifyData(Long orderId) {
        Map<String,Object> data = new HashMap<>();

        FieldServiceWorkOrder workOrder = fieldServiceWorkOrderDao.selectByPrimaryKey(orderId);
        data.put("orderNo",workOrder.getWorkOrderNo());
        data.put("orderStatus",workOrder.getStatus());

        FieldServiceItem item = fieldServiceItemDao.selectByPrimaryKey(workOrder.getItemId());
        data.put("itemNo",item.getItemNo());

        return data;
    }

    @Override
    public List<UserT> getEngineers(Long orderId) {
        List<UserT> userList = new ArrayList<>();
        FieldServiceWorkOrder workOrder = fieldServiceWorkOrderDao.selectByPrimaryKey(orderId);
        if(null != workOrder){
            UserT userT = userTDao.selectById(workOrder.getEngineerId());
            if(null != userT){
                userList.add(userT);
            }
        }
        return userList;
    }
}
